/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.formaters.om;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.utils.*;
import fr.ove.openmath.jome.model.*;
import fr.ove.openmath.jome.formaters.om.*;

/**
* Formats the formula tree structure as its corresponding OpenMath object.<BR>
* This is the formater of the float element.
*
* @author © 2000 DIRAT Laurent
* @version 1.0 07/01/2000
*/
public class VariableOrNumberFormater implements Formater {
    /**
    * Returns the specified object formatted as a string.
    * @param formatedObject the formatted object (for structured object, could represents the beginning).
    * @param formaterRepository where the different other formaters are.
    * @param obj the object to format.
    */
    public String format(String formatedObject, FormaterRepository formaterRepository, Object obj) {
        VariableOrNumber fts = (VariableOrNumber) obj;
        
        if (!fts.isTemplate()) {
            OpenMathFormater omFormater = (OpenMathFormater) formaterRepository;
            if (fts.isNumber()) {
                if (!fts.isInteger())
                    formatedObject += omFormater.writeFloat(fts.getValue());
                else
                    formatedObject += omFormater.writeInteger(fts.getValue());
            }
            else if (fts.isRequestVariable()) {
                formatedObject += omFormater.writeStartApplication();
                formatedObject += omFormater.writeSymbol("mfd2", "request_variable");
                formatedObject += omFormater.writeVariable(fts.getValue());
                formatedObject += omFormater.writeEndApplication();
            }
            else
                formatedObject += omFormater.writeVariable(fts.getValue());
        }
                
        return formatedObject;
    }
}